﻿///<reference path="~/Scripts/scene.statemanager.js" />
///<reference path="~/Scripts/scene.layoutservice.js" />

//Contains the initial screen startup
var startup = function () {
    $.ajaxSetup({ cache: false });

    var windowFocused = true,
        login,

    init = function (pLogin) {
        login = pLogin;

        // Track if user switches tabs or not otherwise
        // Timers may queue up in some browsers like Chrome
        //$(window).focus(function () {
        //    windowFocused = true;
        //});

        //$(window).blur(function () {
        //    windowFocused = false;
        //});

        // Events to top buttons
        $('#gridButton').click(function () {
            if (!$('#gridButton').attr('disabled'))
                sceneStateManager.changeScene();
        });

        $('#cloudButton').click(function () {
            if (!$('#cloudButton').attr('disabled'))
                sceneStateManager.changeScene();
        });

        // Create page view base of defined layout
        var defaultPositions = sceneLayoutService.get();        
        sceneStateManager.init(defaultPositions);
        sceneStateManager.renderTiles(login);

        setTimeout(function () {
            $('.tile').each(function () {               
                    $(this).fadeIn(360, 'easeInCubic');
                });
            },
            1000);

        // Update Your account on timer basis
        setInterval(function (){
                if (!windowFocused)
                    return;
                sceneStateManager.renderYourAccount();
                sceneStateManager.renderBestPlayers();
                sceneStateManager.renderLastGame();
            }, 
            15000);       
    },

     getLogin = function () {
         return login;
     };
    
    return {
        init: init,
        getLogin: getLogin       
    };

} ();

